<%String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="<%=path%>/media/js/jquery.1.9.js" ></script>
    <title>简易设备资产管理系统</title>
   
  </head>
  <body style="">

    <div style="margin-left: auto;margin-right: auto;">
      <h2>简易设备资产管理系统</h2>
      <br>
        <table>
          <tr>
            <td>用户名</td>
            <td colspan="2">
              <input type="text" name="username" id="username" />
            </td>
          </tr>
          <tr>
            <td>密码</td>
            <td colspan="2">
              <input type="password" name="password" id="password" />
            </td>
          </tr>
          <tr  ><td colspan="3" ><p id="notice" style="display: none;" >用户名或密码错误</p></td></tr>
          <tr>
            <td><button onclick="adminLogin()">管理员登录</button></td>
            <td><button onclick="userLogin()" >用户登录</button></td>
            <td><a href="register.html"><button>注册</button></a></td>
          </tr>
        </table>


    </div>

  </body>

<script>


  var username = $("#username").val();
  var pwd = $("#password").val();


  function initLogin(name, pwd) {
    if (isNull(name)){$("#username").focus();console.log("----username is null");}
    else if (isNull(pwd)){$("#password").focus()}
    else return true;
  }

  function adminLogin() {
    var username = $("#username").val();
    var pwd = $("#password").val();
    var path = "<%=path%>";

    if (initLogin(username, pwd)) {
      $.ajax({
        url:'doAdminLogin.html',
        type:'post',
        dataType:'json',
        data:{
          username : username,
          password : pwd
        },
        success : function(rd) {

          if (rd) {
            window.location.href = path + "/adminIndex.html";
          } else {
            $("#notice").css("display", "block");
          }
        }
      })

    }
  }

  function userLogin() {
    var username = $("#username").val();
    var pwd = $("#password").val();
    var path = "<%=path%>";


    if (initLogin(username, pwd)) {
      $.ajax({
        url:'doLogin.html',
        type:'post',
        dataType:'json',
        data:{
          username : username,
          password : pwd
        },
        success : function(rd) {

          console.log("is ---- " + rd);

          if (rd) {
            var newPath = path + "/userIndex.html";
            console.log(newPath);
            window.location.href = path + "/userIndex.html";
          } else {
            console.log("false ---- ");
            $("#notice").css("display", "block");
          }
        }

      })
    }
  }



  function isNull(obc) {
    return (obc == null || obc.length <= 0);
  }

</script>
</html>